Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix back-button history for turbo-frames #103

Merged
merged 1 commit into from
Feb 2, 2024
Merged

Conversation

krschacht
Copy link
Contributor

@krschacht krschacht commented Feb 1, 2024

There is an issue with turbo-frame elements where you can target them to be updated while preserving the overall page state, but the URL does not change to reflect this and the browse back button does not work. This may be intended behavior or it may be a bug with Turbo, I can't tell. I have an open issue with them here: hotwired/turbo#1156

But regardless, we want it to work because clicking a conversation in the left sidebar refreshes the turbo-frame id="conversation" in the right side. We do the frame refreshing because we want the scroll position of the left side to remain preserved.

This works by manually updating the browser's pushState and manually handling the back button for these cases. Demo here: https://share.zight.com/jku8YrZLj

@krschacht krschacht requested a review from robacarp February 1, 2024 23:34
Copy link
Contributor

@robacarp robacarp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is awesome. it would be good to write a rails system test for this, I don't think it would be hard at all to represent this in there.

@krschacht
Copy link
Contributor Author

this is awesome. it would be good to write a rails system test for this, I don't think it would be hard at all to represent this in there.

Good call, I'll start a new PR with tests. I want to add tests for a few of these stimulus things I've done recently.

@krschacht krschacht merged commit e82e04d into main Feb 2, 2024
4 checks passed
@krschacht krschacht deleted the fix-frame-history branch February 2, 2024 16:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants